home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / cli / bangtools.lha / src / memcopy.c < prev    next >
C/C++ Source or Header  |  1995-01-15  |  2KB  |  86 lines

  1. /* memcopy - copy bytes from one memory location to another
  2.  *
  3.  * Copyright (C) 1994 by Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose and without fee is hereby granted, provided
  7.  * that the above copyright notice appear in all copies and that both that
  8.  * copyright notice and this permission notice appear in supporting
  9.  * documentation.  This software is provided "as is" without express or
  10.  * implied warranty.
  11.  *
  12.  * V1.0: 09/Dec/94 first version
  13.  */
  14. #define THIS_PROGRAM    "memcopy"
  15. #define THIS_VERSION    "1.0"
  16.  
  17. #include <exec/types.h>
  18. #include <exec/libraries.h>
  19. #include <dos/dos.h>
  20. #include <dos/rdargs.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23.  
  24. #define SysBase_DECLARED
  25. #include <proto/exec.h>
  26. #include <proto/dos.h>
  27. #include <proto/utility.h>
  28.  
  29. extern struct Library *SysBase;
  30.  
  31. static const char amiga_version[] = "\0$VER: " THIS_PROGRAM " " THIS_VERSION " (" __COMMODORE_DATE__ ")";
  32.  
  33. const char Template[] = "FROM/A,TO/A,NUM/N,STRING/S";
  34. __aligned struct {
  35.     STRPTR  from;
  36.     STRPTR  to;
  37.     LONG *  num;
  38.     LONG    isstring;
  39. } Args;
  40.  
  41. void
  42. _main()
  43. {
  44.     struct RDArgs *rdargs;
  45.     APTR addr1, addr2;
  46.     LONG rc = RETURN_OK;
  47.  
  48.     if( SysBase->lib_Version < 37 ) {
  49.         #define MESSAGE "requires AmigaOS 2.04 or higher\n"
  50.         Write(Output(), MESSAGE, sizeof(MESSAGE)-1);
  51.         _exit(RETURN_FAIL);
  52.         #undef MESSAGE
  53.     }
  54.  
  55.     if( rdargs = ReadArgs(Template, (LONG *)&Args, NULL) ) {
  56.         char *endp1, *endp2;
  57.         addr1 = (APTR)strtoul(Args.from, &endp1, 0);
  58.         addr2 = (APTR)strtoul(Args.to  , &endp2, 0);
  59.         if( *endp2 ) {
  60.             PutStr("invalid address\n");
  61.             rc = RETURN_ERROR;
  62.         }
  63.         else {
  64.             if( *endp1 || Args.isstring ) {  /* FROM arg is a string */
  65.                 if( Args.num )
  66.                     strncpy((char *)addr2, Args.from, *(Args.num));
  67.                 else
  68.                     strcpy((char *)addr2, Args.from);
  69.             }
  70.             else {
  71.                 if( Args.num )
  72.                     CopyMem(addr1, addr2, *(Args.num));
  73.                 else
  74.                     strcpy((char *)addr2, (char *)addr1);
  75.             }
  76.         }
  77.         FreeArgs(rdargs);
  78.     }
  79.     else {
  80.         PutStr("required argument missing\n");
  81.         rc = RETURN_ERROR;
  82.     }
  83.     _exit((int)rc);
  84. }
  85.  
  86.